package com.example.yifei.ui.page.main.demand.tab

import android.annotation.SuppressLint
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.NavHostController
import androidx.paging.compose.collectAsLazyPagingItems
import androidx.paging.compose.itemsIndexed
import coil.annotation.ExperimentalCoilApi
import com.example.yifei.ui.page.main.demand.tab.item.DemandItem
import com.example.yifei.ui.page.widgets.RefreshList

/**
 * @Author: zhudaihao
 * @Date: 2022/5/12
 * @Describe: 待确认
 */

@ExperimentalCoilApi
@SuppressLint("RememberReturnType")
@ExperimentalMaterialApi
@Composable
fun ConfirmationPage(
    navCtrl: NavHostController,
    viewModel: ConfirmationViewMode = hiltViewModel()
) {
    val viewStates = remember { viewModel.viewStates }
    val squareData = viewStates.pagingData.collectAsLazyPagingItems()
    val listState = if (squareData.itemCount > 0) viewStates.listState else LazyListState()

    RefreshList(squareData, listState = listState) {
        itemsIndexed(squareData) { _, it ->
            DemandItem(it, navCtrl = navCtrl)
        }
    }

}

